	validForm = false;
	
	submit  = document.getElementById("submit");
	/** cek ke-valid-an link_url */
	document.getElementById("link_url").addEventListener("blur", linkValidator, false);
	document.getElementById("link_url").addEventListener("keydown", linkValidator, false);
	textval = document.getElementById("link_url").value;
	
        function linkValidator() {
                var urlregex = new RegExp(
                        "^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&amp;%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&amp;%\$#\=~_\-]+))*$");
                valid_url = urlregex.test(textval);

                if (document.getElementById("link_url").value.match(valid_url)){
                        document.getElementById("linkValidator").innerHTML="";
                        validForm= true;
                }
                else {
                        document.getElementById("linkValidator").innerHTML="Link tidak valid";
                        validForm = false;			
                }
        }
	
	function preview()
	{
		if (document.getElementsByName("option")[0].checked){
			document.getElementById("preview").innerHTML="<h1>Preview Link Posting</h1><h2>"+ document.getElementById("form_nama").value+"</h2><h3>Link : <a href="+document.getElementById("form_link").value+">"+document.getElementById("form_link").value+"</a></br>Description: "+ document.getElementById("form_link_description").value+"</h3>";
		}
		else if(document.getElementsByName("option")[1].checked){
			//document.getElementById("preview").innerHTML="<h1>Preview Image Posting</h1><h2>Trolling di MiniMarket</h2><img src='images/trollingMiniMarket.jpg'></img>";
		}
		else if(document.getElementsByName("option")[2].checked) {
			document.getElementById("preview").innerHTML='<h1>Preview Video Posting</h1><h2>'+ document.getElementById("form_nama").value+'</h2>'+document.getElementById("form_video").value;
		}	
	}

	function link_enable(){
		document.posting_form.link_url.disabled=false;
		document.posting_form.link_description.disabled=false;
		document.posting_form_image.gambar.disabled=true;
		document.posting_form.mov.disabled=true;
	} 
	function image_enable(){
		document.posting_form.link_url.disabled=true;
		document.posting_form.link_description.disabled=true;
		document.posting_form_image.gambar.disabled=false;
		document.posting_form.mov.disabled=true;
	}
	function video_enable(){
		document.posting_form.link_url.disabled=true;
		document.posting_form.link_description.disabled=true;
		document.posting_form_image.gambar.disabled=true;
		document.posting_form.mov.disabled=false;
	}
	
	/** cek ke-valid-an email */
	document.getElementById("email").addEventListener("blur", emailValidator, false);
	document.getElementById("email").addEventListener("keydown", emailValidator, false);
	function emailValidator()
	{
		if (validString(document.getElementById("email").value, /[\w.]{5,}@[\w.]{2,}\.[\w.]{2,}/)) {
			document.getElementById("emailValidator").innerHTML="";
			validForm[5] = true;
		} else {
			document.getElementById("emailValidator").innerHTML="email minimal terdiri dari 5 karakter yang terdiri atas huruf, angka, '_', dan '.' saja dan diikuti oleh @ domain yang minimum terdiri dari 2 karakter yang terdiri atas huruf, angka, '_', dan '.' saja";
			validForm[5] = false;
		}
		allowSubmission();
		passwordValidator();
		passwordlagiValidator();
	}
	
	/** cek ke-valid-an gender */
	document.getElementById("gender").addEventListener("blur", genderValidator, false);
	document.getElementById("gender").addEventListener("click", genderValidator, false);
	function genderValidator()
	{
		if (document.getElementById("gender").value != "Pilih Kelamin") {
			document.getElementById("genderValidator").innerHTML="";
			validForm[7] = true;
		} else {
			document.getElementById("genderValidator").innerHTML="Jenis kelamin anda harus diisi";
			validForm[7] = false;
		}
		allowSubmission();
	}
	function validString (str, reg) {
		return (reg.test(str));
	}
	
	function allowSubmission () {
		var valid = true;
		
		for (var i = 0; i < 8; ++i)
			if (! validForm[i])
				valid = false;
		
		if (valid)
			submit.removeAttribute("disabled");
	}
        
        // ajax function to process form
        function postingProcess(){
            
            var p = document.getElementsByName("option");
            var optionResult = 0;
            for (i = 0; i < p.length; i++) {
                if (p[i].checked) {
                    optionResult = p[i].value;
                }
            }
            var pathFile = "";
            
            var titleContent = document.getElementsByName("title")[0].value;
            var linkURL = document.getElementsByName("link_url")[0].value;
            var linkDescription = document.getElementsByName("link_description")[0].value;
            var videoContent = document.getElementsByName("mov")[0].value;
            var tagContent = document.getElementsByName("tag")[0].value;
            if (optionResult == "image"){
                pathFile = document.getElementsByName("path")[0].value;
            }        
            
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    document.getElementById('message').innerHTML=xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","PostingHandler.jsp?titleContent="+titleContent+"&optionResult="+optionResult+"&linkURL="+linkURL+"&linkDescription="+linkDescription+"&videoContent="+videoContent+"&tagContent="+tagContent+"&pathFile="+pathFile, true);
            xmlhttp.send();
            
        }
        
        